package com.atguigu.dga.ds.service.impl;

import com.atguigu.dga.ds.bean.TDsTaskInstance;
import com.atguigu.dga.ds.mapper.TDsTaskInstanceMapper;
import com.atguigu.dga.ds.service.TDsTaskInstanceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.dynamic.datasource.annotation.DS;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangchen
 * @since 2024-07-31
 */
@Service
@DS("ds")
public class TDsTaskInstanceServiceImpl extends ServiceImpl<TDsTaskInstanceMapper, TDsTaskInstance> implements TDsTaskInstanceService {


    // 每张表的所有任务实例
    @Override
    public Map<String, List<TDsTaskInstance>> getTaskInstanceListMap() {
        List<TDsTaskInstance> allTaskInstanceList = this.list(); //所有表所有任务
        Map<String, List<TDsTaskInstance>>  taskInstanceListMap = new HashMap();
        for (TDsTaskInstance tDsTaskInstance : allTaskInstanceList) {
            //尝试从map中获取List //如果获取不到，则创建一个新list

            List<TDsTaskInstance> tDsTaskInstanceList = taskInstanceListMap.get(tDsTaskInstance.getName());
            //如果有 直接把自己加入到集合中，如果没有新建一个 List ,在把自己加入
            if(tDsTaskInstanceList==null){
                tDsTaskInstanceList = new java.util.ArrayList<>();
                taskInstanceListMap.put(tDsTaskInstance.getName(),tDsTaskInstanceList);
            }
            tDsTaskInstanceList.add(tDsTaskInstance);

        }
        return taskInstanceListMap;
    }
}
